package control
{
	import flash.events.Event;
	
	import model.ModelLocator;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.http.HTTPService;
	import mx.rpc.remoting.RemoteObject;
	
	import view.Plans;
	public class sharePath
	{
		internal var theModel:ModelLocator = ModelLocator.getInstance();
		private var shareRO:RemoteObject;
		private var sharePathHttp:HTTPService;
		private var showSharePathHttp:HTTPService;
		private var deleteShareHttp:HTTPService;
		public function sharePath()
		{
			shareRO = new RemoteObject();
			shareRO.destination = "sharepath";
			shareRO.sharePath.addEventListener(ResultEvent.RESULT,resultHandler);
			shareRO.showSharePath.addEventListener(ResultEvent.RESULT,showResultHandler);
			shareRO.deleteShare.addEventListener(ResultEvent.RESULT,deleteResultHandler);
			shareRO.addEventListener(FaultEvent.FAULT, fHandler);
		}
		public function share(id:int,pathid:int):void{
			shareRO.sharePath(id,pathid);
		}
		public function show():void{
			shareRO.showSharePath(theModel.user.user_id);
		}
		
		public function deleteShare(o:Object):void{
			
			shareRO.deleteShare(theModel.user.user_id,o.pathid);
		}
	
		private function httpEncoding(param:String):String{
                return encodeURIComponent(param);
        }
		internal function resultHandler(event:ResultEvent):void{
       		
       	}
       	internal function deleteResultHandler(event:ResultEvent):void{
       		theModel.dispatchEvent(new Event(ModelLocator.DELETE_SHARE_OK));
       	}
       	internal function showResultHandler(event:ResultEvent):void{
       		//Alert.show(event.result.Result.Plan.username);
       		Plans.myShare=event.result as ArrayCollection;
       		
       	}
		internal function fHandler (event:FaultEvent):void {
         		Alert.show(event.fault.message,"Error1")
        }

	}
}